<?php
/**
 * Created by PhpStorm.
 * DateTime: 2020/11/2 10:50
 * Intro:
 */

namespace addons\podunk\controller;

use addons\podunk\model\PortLog;
use addons\podunk\model\User;


class Dashboard extends Base
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        return parent::_initialize();
    }

    public function getInfo()
    {

        $agentNum = User::where('parent_id',$this->auth->id)->count('id');

        $port = User::where('id',$this->auth->id)->value('port');

        $addPort = PortLog::where(['user_id'=>$this->auth->id, 'port'=>['gt',0], 'memo'=>['LIKE',' 被充值增加%']])->sum('port');
        $reducePort = PortLog::where(['user_id'=>$this->auth->id, 'port'=>['lt',0], 'memo'=>['LIKE',' 被扣除减少%']])->sum('port');

        $allPort = $addPort + $reducePort;

        $this->success('获取成功',[
            'agent_num' => $agentNum,
            'port' => $port,
            'all_port' => $allPort,
            'reduce_prot'=>$reducePort
        ]);
    }
}